package com.qidi.filter;

import com.qidi.utils.JdbcUtils;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author zhouXinBin
 * @create 2020-09-06-15:01
 */
public class Transactionfilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        try {
            filterChain.doFilter(servletRequest,servletResponse);
            JdbcUtils.CommitAndClose();
        } catch (Exception e) {
            JdbcUtils.RollbackAndClose();
            e.printStackTrace();
        }
    }
    @Override
    public void destroy() {

    }
}
